package net.lainiao.morethread.Chapter4.demo4;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Main {
    public static void main(String[] args) {
        String username = "test";
        String password = "test";
        UserValidator validator1=new UserValidator("OGSI");
        UserValidator validator2=new UserValidator("System");
        TaskValidator ogsiTask=new TaskValidator(username,password,validator1);
        TaskValidator systemTask=new TaskValidator(username,password,validator2);
        List<TaskValidator> taskLists=new ArrayList<>();
        taskLists.add(ogsiTask);
        taskLists.add(systemTask);
        ExecutorService executorService=(ExecutorService) Executors.newCachedThreadPool();
        String result;
        try {
            result=executorService.invokeAny(taskLists);
            System.out.println("Main : Result:"+result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            System.out.println("验证失败");
        }
        executorService.shutdown();
        System.out.println("Main:End of the Execution");
    }
}
